package io.renren.modules.maintenance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.modules.maintenance.entity.MWorkSheet;
import io.renren.modules.maintenance.mapper.MWorkSheetMapper;
import io.renren.modules.maintenance.service.IMWorkSheetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author iweb
 * @since 2020-08-07
 */
@Service
public class MWorkSheetServiceImpl extends ServiceImpl<MWorkSheetMapper, MWorkSheet> implements IMWorkSheetService {

    @Autowired
    MWorkSheetMapper mWorkSheetMapper;

    @Override
    public boolean insertWorkSheet(String orderId , int devDetId) {
        MWorkSheet workSheet = new MWorkSheet();
        workSheet.setOrderId(orderId);
        workSheet.setDevDetId(devDetId);
        return this.save(workSheet);
//        return false;
    }

    @Override
    public MWorkSheet getMWorksheetByOrderId(String orderId) {
        MWorkSheet mWorkSheet= mWorkSheetMapper.selectOne(new QueryWrapper<MWorkSheet>().eq("order_id",orderId));
        //如果该订单不存在对应的工作单记录，则新建工作单记录,并创建相应的设备信息记录
        if (mWorkSheet==null){
            mWorkSheet=new MWorkSheet();
            mWorkSheet.setOrderId(orderId);
            mWorkSheetMapper.insert(mWorkSheet);
            mWorkSheet= mWorkSheetMapper.selectOne(new QueryWrapper<MWorkSheet>().eq("order_id",orderId));

        }
        return mWorkSheet;

    }

}
